<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output
               method="html" encoding="UTF-8"
               media-type="text/html"  omit-xml-declaration="yes"
               doctype-public= "-//W3C//DTD XHTML 1.0 Strict//EN"
               doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
               indent="yes"/>   
<xsl:param name="role"/>
<xsl:template match="/pizzeria">
	<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<title><xsl:value-of select="pizzeria/mise_en_forme/titre"/></title>
			<link type="text/css" href="css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
			<link type="text/css" href="css/Affiche.css" rel="stylesheet" />
			<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
			<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
			<script type="text/javascript" src="js/Affiche.js"></script>
			<script type="text/javascript">
			$.getScript('js/Affiche.js',function(){
				mise_en_forme();
				affiche();
				bouton_commande_pizza();
				modif_pizza();
				login_register();
				valider_modif();
				valider_commande();
				bouton_annuler_order();
				bouton_modifier_order();
			});	
			</script>
			<style type="text/css">
				.demoHeaders { margin-top: 2em; }
				#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
				#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
				ul#icons {margin: 0; padding: 0;}
				ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
				ul#icons span.ui-icon {float: left; margin: 0 4px;}
			</style>
		</head>
		
		<xsl:apply-templates select="mise_en_forme"/>
		<xsl:if test="'user'=$role">
			<button id="destroy">logout</button>
		</xsl:if>
			<xsl:if test="'admin'=$role">
			<button id="destroy">logout</button>
		</xsl:if>
	</html>
</xsl:template>

<xsl:template match="mise_en_forme">
	<body>
		<h1>
			<xsl:value-of select="titre"/>
		</h1>
		<div id="tabs">
			<xsl:apply-templates select="onglets"/>
		</div>
	</body>
</xsl:template>

<xsl:template match="onglets">
	<ul>
		<xsl:apply-templates select="onglet"/>
	</ul>
	<xsl:for-each select="onglet">
		<xsl:variable name="nomOnglet" select="@name" />
		<div id="{$nomOnglet}">
			<xsl:if test="'pizzas'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/pizzas"/>			
			</xsl:if>
			<xsl:if test="'boissons'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/boissons"/>			
			</xsl:if>
			<xsl:if test="'menus'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/menus"/>			
			</xsl:if>
			<xsl:if test="'compte'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/commandes"/>			
			</xsl:if>
			<xsl:if test="'commandes'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/commandes"/>			
			</xsl:if>
			<xsl:if test="'connection'=$nomOnglet">
				<xsl:apply-templates select="/pizzeria/connection"/>			
			</xsl:if>
		</div>
	</xsl:for-each>
</xsl:template>
<xsl:template match="connection">
	<form method="post" id="login" action="">
	    <h2>Connection</h2>
	    <fieldset id="inputs">
	        <input id="username" type="text" placeholder="Username" /><br/>
	        <input id="password" type="password" placeholder="Password"/>
	    </fieldset>
	    <fieldset class="actions">
	        <button id="login-user">Connection</button>
	        <button id="register-user">Register</button>
	    </fieldset>
	</form>
	<div id="dialog" title="Enregistrement">
		<p class="validateTips">All form fields are required.</p>
		<form>
		<fieldset>
			<label class="register" for="email">Email</label>
			<input type="text" name="email" id="register-email" value="" class="text ui-widget-content ui-corner-all" /><br/>
			<label class="register" for="password">Password</label>
			<input type="password" name="password" id="register-password" value="" class="text ui-widget-content ui-corner-all" />
		</fieldset>
		</form>
	</div>
</xsl:template>
<xsl:template match="onglet">
	<xsl:variable name="inter" select="@name" />
	<xsl:variable name="nomID" select="concat('id_',$inter)"/>
	<xsl:variable name="nomOnglet" select="concat('#',$inter)"/>
	<li id="{$nomID}" class="{$inter}">
		<a  class="{$nomOnglet}" href="{$nomOnglet}">
			<xsl:value-of select="$inter"/>
		</a>
	</li>
</xsl:template>
	
<xsl:template match="pizzas">
	<table id="table_pizzas">
		<xsl:apply-templates select="pizza"/>
	</table>
</xsl:template>

<xsl:template match="boissons">
	<table id="tableau_boissons">
		<xsl:apply-templates select="boisson"/>
	</table>
</xsl:template>
<xsl:template match="menus">
	<table id="tableau_menus">
		<xsl:apply-templates select="menu"/>
	</table>
</xsl:template>

<xsl:template match="commandes">
	<xsl:if test="panierpizzas">
		<xsl:if test="'user'=$role">
			<xsl:apply-templates select="panierpizzas"/>
			<button id="valider-commande"> commander </button>
			<button id="annuler-order"> annuler </button>
		</xsl:if>	
		<xsl:if test="'admin'=$role">
			<div id="commandesList">
				<xsl:apply-templates select="panierpizzas"/>
			</div>
		</xsl:if>	
	</xsl:if>
</xsl:template>

<xsl:template match="panierpizzas">
	<xsl:if test="'user'=$role">
		<table id="panier-pizzas">
		<tr class="bas">
			<td colspan="4">
				panier pizzas
			</td>
		</tr>
			<xsl:apply-templates select="commandepizza"/>
		</table>
	</xsl:if>
	<xsl:if test="'admin'=$role">
		<xsl:variable name="nomclient" select="@idClient"/>
		<xsl:variable name="idCommande" select="@idCommande"/>
		<xsl:variable name="prix" select="@prix"/>
		<xsl:variable name="status" select="@status"/>
			<h4>
				<a href="#">
					<xsl:value-of select="concat('commande :',$idCommande,' ')"/>
					<xsl:value-of select="concat($nomclient,' ')"/>
					<xsl:value-of select="concat($prix,'€')"/>
					<xsl:value-of select="concat(' status :',$status)"/>
				</a>
			</h4>
			<div>
				<table class="panier-pizzas">
				<tr class="bas">
					<td colspan="4">
						commandes de pizzas
					</td>
				</tr>
					<xsl:apply-templates select="commandepizza"/>
				</table>
				<button idCommande="{$idCommande}" class="annuler-commande">
					annuler
				</button>
				<button idCommande="{$idCommande}" class="status-suivant">
					status suivant
				</button>
			</div>
	</xsl:if>
</xsl:template>

<xsl:template match="commandepizza">
	<tr class="bas">
		<td>
			<xsl:value-of select="@name"/>
		</td>
		<td>
			<xsl:value-of select="@size"/>
		</td>
		<td>
			<xsl:value-of select="@qty"/>
		</td>
		<td>
			<xsl:value-of select="@price"/>
		</td>
	</tr>
</xsl:template>
<xsl:template match="boisson">
	<tr>
		<xsl:variable name="image" select="concat('images/boissons/',@id,'.gif')"/>
		<th rowspan="2">
			<img src="{$image}"/>
		</th>
		<td rowspan="2">
			<xsl:value-of select="nomBoisson"/>
		</td>
		<td rowspan="2">
			<xsl:value-of select="contenance"/>
		</td>	
		<td rowspan="2">
			<xsl:value-of select="prix"/>
		</td>	
		<td rowspan="2">
			<xsl:variable name="achatBoisson" select="@id" />
			<button idBoisson="{$achatBoisson}" class="#button">
				commander
			</button>
		</td>			
	</tr>
</xsl:template>
<xsl:template match="menu">
	<tr>
			<xsl:variable name="image" select="concat('images/menu/',@id,'.gif')"/>								
			<th rowspan="2">
				<img src="{$image}"/>
			</th>
			<td rowspan="2">
				<xsl:value-of select="nomMenu"/>
			</td>
			<td colspan="2">
				<xsl:variable name="nbPizzas" select="concat('vous avez le droit à ',nbPizzas,' pizzas')"/> 
				<xsl:value-of select="$nbPizzas"/>
			</td>	
			<td rowspan="2">
				<xsl:value-of select="prix"/>
			</td>	
			<td rowspan="2">
				<xsl:variable name="achatPizza" select="@id" />
				<button idPizza="{$achatPizza}" class="#button">
					commander
				</button>
			</td>			
		</tr>
		<tr class="bas">
			<td colspan="2">
				<xsl:variable name="nbBoissons" select="concat('vous avez le droit à ',nbBoissons,' boissons')"/> 
				<xsl:value-of select="$nbBoissons"/>
			</td>			
		</tr>
</xsl:template>
<xsl:template match="pizza">
<xsl:variable name="idpizza" select="@id" />
	<tr>
			<xsl:variable name="image" select="concat('images/pizzas/',@id,'.gif')"/>								
			<th rowspan="2">
				<img src="{$image}"/>
			</th>
			<td rowspan="2" content="nomPizza">
				<xsl:value-of select="nomPizza"/>
			</td>
			<td colspan="2" content="nombase">
				<xsl:variable name="nombase" select="concat('base ',base)"/> 
				<xsl:value-of select="$nombase"/>
			</td>	
			<td rowspan="2" content="prix">
				<xsl:value-of select="prix"/>
			</td>	
			<xsl:if test="'admin'=$role">
				<td rowspan="2" class="bouton-pizza">
					<button idPizza="{$idpizza}" class="button_modif_pizza">
						modifier
					</button>
				</td>		
			</xsl:if>	
			<xsl:if test="'user'=$role">
				<td rowspan="2" class="bouton-pizza">
					<button idPizza="{$idpizza}" class="button_order_pizza">
						commander
					</button>
				</td>		
			</xsl:if>	
		</tr>
		<tr class="bas">
			<td  colspan="2" class="trait-tab" content="ingredients" idPizza="{$idpizza}">
				<xsl:apply-templates select="ingredients/ingredient"/>
			</td>			
		</tr>
</xsl:template>
<xsl:template match="ingredient">
	<xsl:if test="selected='ok'">
		<xsl:variable name="space" select="concat(nom,'  ')"/>
		<xsl:value-of select="$space"/>
	</xsl:if>
</xsl:template>
</xsl:stylesheet>